<div class="fsh-rightPanel">
    <div class="layui-anim layui-anim-upbit">
        <div id="list_form_authorize_school" class="layui-form-item wx-search">
            <div class="layui-inline">
                <input type="text" name="schoolName" placeholder="请输入名称" autocomplete="off" class="layui-input">
            </div>
            <button id="search_school" class="layui-btn btn-primary">搜索</button>
        </div>
        <table id="squadList" class="layui-hide" lay-filter="squadList"></table>
    </div>
</div>
<script type="text/html" id="toolBar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addSquad">添加班级</button>
    </div>
</script>
<script>
    layui.use(['layer', 'table'], function () {
        var layer = layui.layer;
        var table = layui.table;
        var tableObj2 = table.render({
            elem: '#squadList'
            //开启头部工具栏，并为其绑定左侧模板，
            , toolbar: '#toolBar'
            , url: context + '/api/eduCoursePlanAuth/list?type=2&plan_id=' + ('<%=course_plan_id||"0"%>')
            , page: true
            , request: {
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , align: 'center'
            , cols: [[ //表头
                {field: 'principalCode', title: '班级代码', align: 'center', width: 150},
                {
                    title: 'LOGO', align: 'center', templet: function (d) {
                        return d._eduSquad ? '<div><img src="' + (d._eduSquad.logo||'./res/images/index-header.jpg') + '" style="height:100px;width:100px;" alt=""/></div>' : '';
                    }
                },
                {title: '名称', align: 'center', templet: function (d) {return d._eduSquad? d._eduSquad.squad_name:'';}},
                {field: 'createDate', title: '分配日期', align: 'center'}
                , {
                    title: '操作', width: 100, align: 'center', unresize: true,
                    templet: function (d) {
                            return '<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>'
                    }
                }
            ]]
        });

        // 检索
        $("#search_school").click(function () {
            reloadTable(tableObj2,'list_form_authorize_school');
        });

        //头工具栏事件
        table.on('toolbar(squadList)', function (obj) {
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'addSquad') {
                showDialog({
                    formId: 'add_form_plan_squad'
                    , title: '添加班级'
                    , tableObj: tableObj2
                    , template: context + '/views/school/plan/template/addSquad.html'
                    , htmlData: { course_plan_id: '<%=course_plan_id%>'}
                    , saveUrl: context + '/api/eduCoursePlanAuth/addSquad'
                    , type: 'POST'
                    , dataType: 'json'
                })
            }
        });
        //表格内部操作按钮监听
        table.on('tool(squadList)', function (obj) { //注：tool是工具条事件名，mainList是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            if (layEvent === 'del') {
                confirmDel(context + '/api/eduCoursePlanAuth/del/'+ data.auth_plan_id, tableObj2);
            }
        });

    });
</script>
